package cn.sxt.yxl.common.util;

import java.util.Map;
import java.util.concurrent.Callable;

import cn.sxt.yxl.question.service.IQuestionSpiderService;

/**
 * 新版的多线程
 * 
 * @author wangshSxt
 *
 */
public class MutliThreadUtil implements Callable<Object>
{
	private String name;
	/* 参数 */
	private Map<String, Object> paramsMap ;

	public MutliThreadUtil(String name)
	{
		super();
		this.name = name;
	}

	@Override
	public Object call() throws Exception
	{
		/*Thread.sleep(3000);
		ConstatFinalUtil.LOGGER.info("多线程执行~~name:{}~~线程名:{}",
				this.name , 
				Thread.currentThread().getName());*/
		/* 
		 * 因为这个多线程可能做其它的事情
		 * 标识
		 * 必传operType和栏目的url
		 *  */
		String operType = paramsMap.get("operType") + "";
		if("spliderColumns".equalsIgnoreCase(operType))
		{
			/* 为指定的栏目采集数据 */
			this.spliderColumns(paramsMap);
			/*ConstatFinalUtil.LOGGER.info("多线程执行~~name:{}~~线程名:{}",
					this.name , 
					Thread.currentThread().getName());*/
		}
		return null;
	}

	private void spliderColumns(Map<String, Object> paramsMap)
	{
		/* 取到栏目的URL */
		String url = paramsMap.get("url") + "";
		IQuestionSpiderService questionSpiderService = (IQuestionSpiderService) paramsMap.get("questionSpiderService");
		questionSpiderService.saveBatchItemsService(url);
	}

	public Map<String, Object> getParamsMap()
	{
		return paramsMap;
	}

	public void setParamsMap(Map<String, Object> paramsMap)
	{
		this.paramsMap = paramsMap;
	}

}
